var NodeRSA = require('node-rsa');
var fs= require('fs'); 
 
var onerror =(e) =>{
    console.log("解密失败");
 
}
var onfinally =() =>{
    console.log("最终做什么");
}
 
 
fs.readFile('rsa_private.key','utf-8',function(err,data){ 
    if(err){ 
        console.log(data); 
    }else{ 
        console.log(data); 
        privatekey= new NodeRSA(data);
            var text = 'Hello RSA!';
            var encrypted = privatekey.encrypt(text, 'base64');
            console.log('加密encrypted: ', encrypted);
            var decrypted = privatekey.decrypt(encrypted, 'utf8');
            console.log('解密decrypted: ', decrypted);
            var encrypted1 ='mIJocRfF+MWS3J6+fkPSM9ZAMSZhXxHC+/w0UuT+t6ZmLnoamQ6WKwOBPQ+o+mazk61MFdyImWVW+51dYLc7kE4Eey4y+qB23/ahC9Mi/bJqivWgUHeLPjfLMqXcNVrFSbOB33+7N/fsWAWLJmHuFHaNwP1DqPLH9nY501qoMvY=';
            var decrypted = privatekey.decrypt(encrypted1, 'utf8');
            console.log('使用正确的加密串解密decrypted: ', decrypted);
 
            try{
                var encrypted2 ='c7kE4Eey4y+qB23/ahC9Mi/bJqivWgUHeLPjfLMqXcNVrFSbOB33+7N/fsWAWLJmHuFHaNwP1DqPLH9nY501qoMvY=';
                var decrypted = privatekey.decrypt(encrypted2, 'utf8');
                 
            }catch(e){
                onerror(e);
            }finally{
                onfinally();
            }
 
    } 
}) 